<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="姓名" width="240">
        <template slot-scope="scope">
          <router-link
            :to="{
              path: '/send_message',
              query: { student_num: scope.row.student_num },
            }"
          >
            {{ scope.row.student_name }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="学号" width="240">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.student_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专业" width="240">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.student_class }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">
            <router-link
              :to="{
                path: '/send_message',
                query: { student_num: scope.row.student_num },
              }"
            >
              发送留言
            </router-link>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  created () {
    this.getstudentinfo();
  },
  data () {
    return {
      tableData: [],
    };
  },
  methods: {
    // 获取所带学生信息
    getstudentinfo () {
      this.$http
        .get("http://127.0.0.1:8080/teacher/getStudentInfo")
        .then((res) => {
          // console.log(res);
          if (res.data.status == 0) {
            res.data.data.resul.forEach((value) => {
              res.data.data.result.forEach((val) => {
                if (value.student_num === val.student_num) { Object.assign(val, { topic_name: value.topic_name }); }
              });
            });
            this.tableData = res.data.data.result;
            // console.log(this.tableData.student_name);
          } else {
            this.tableData = [];
          }
        });
    },
    handleEdit (index, row) {
      // console.log(index, row);
    },
  },
};
</script>
<style lang="less" scoped>
</style>
